package com.qf.zyh.web.controller;

import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.entity.Customer;
import com.qf.zyh.services.CustomerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerServices customerServices;

    @RequestMapping("/add")
    public ResponseResult addCus(Customer c){
        try {
            return customerServices.addCus(c);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseResult.getFail("新增失败");
    }
    @RequestMapping("/update")
    public ResponseResult updateCus(Customer c){
        try {
            return customerServices.updateCus(c);
        } catch (Exception e) {
            e.printStackTrace();
        }
            return ResponseResult.getFail("修改失败");
    }
    @RequestMapping("/del")
    public ResponseResult delCus(Integer[] ids){
        try {
                return customerServices.delCus(ids);
            } catch (Exception e) {
                e.printStackTrace();
            }
                return ResponseResult.getFail("删除失败");
        }

    @RequestMapping("/table")
    public ResultType tableCus(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "5") Integer limit, String username, Integer state){
        return customerServices.tableCus(page,limit,username,state);
    }
    @RequestMapping("/tree")
    public List<Customer> tableCus(){
        return customerServices.tree();
    }


}
